package testView;

import static org.junit.Assert.*;

import java.util.Vector;

import org.junit.Test;

import model.*;
/**
*   @version Iteration 3 March 21, 2011
*	@author Team EBE
*	CSCI 420 UML Diagram Software Engineering Project
*
*	Tests the DiagramImpl.java and ClassEditor.java Models.
*	Specifically, this tests creating a diagram and allowing
*	the user to edit the class, such as adding attributes 
*	and operations.
*/

public class UMLTest{
	
	
	AnchorPoint Tester1 = new AnchorPoint(0, 1, "test", 1);
	AnchorPoint Tester2 = new AnchorPoint(2, 3, "test1", 2);
	
	ClassImpl Test = new ClassImpl();
	ClassImpl Test2 = new ClassImpl();
		
	// this method tests creating a new diagram and setting a size
/**
*	This method tests the creation of a new diagram and 
*	assigning it a set size. 
*/
	@Test
	public void testDiagram(){
		
		DiagramImpl d = new DiagramImpl();
		int sizex;
		int sizey;
		
		sizex = d.getSizeX();
		sizey = d.getSizeY();
		
		assertEquals(sizex, 1024);
		assertEquals(sizey, 768);
		
	}
	
/**
*	This method tests the creation of a new diagram and 
*	adding a class to the diagram. The class will contain
*	an attribute and operation and verifies that the diagram
*	is not empty. 
*/
	@Test
	public void testDiagramBuild(){
		
		DiagramImpl d1 = new DiagramImpl();
		String A1 = "AttributeImpl 1";
		String O1 = "OperationImpl 1";
		String C1 = "Class 1";
		

		
		d1.addClass(C1);
		d1.getClassImpl(0).addAttribute(A1, "string", '+');
		d1.getClassImpl(0).addOperation(O1, "char", '-');
		
		
		assertNotNull(d1);
		
		
	}
	
/**
*	This method tests the creation of a relationship
*	between two classes contained in a diagram. It 
*	tests that the anchor points exist and are not the 
*	same for both source and destination.
*/
	@Test
	public void DiagramRelationTest(){
		
		DiagramImpl d3 = new DiagramImpl();
		
		d3.addRelationship(Tester1, Tester2);
		
		assertNotNull(Tester1);
		assertNotNull(Tester2);
		
		assertNotSame(Tester1, Tester2);	
	}
	
	// this method tests to see if attributes and operations exist, and then checking to see if the editor exists
/**
*	This method tests if the class editor is 
*	operating correctly. It tests the operations 
*	such as getAttributes/Operations, setWidth,
*	setHeight, setoX, and setoY return the correct
*	information.
*/
	@Test
	public void ClassEditorTest(){
		
		int sizeX = 2;
		int sizeY = 3;
		
		Test.getAttributes();
		
		assertNotNull(Test);
		
		Test2.getOperations();
		
		assertNotNull(Test2);
			
		Test.setWidth(sizeX);
		Test2.setHeight(sizeY);
		
		assertNotSame(Test, Test2);
		
		assertEquals(2, Test.getWidth());
		assertEquals(3, Test2.getHeight());
		
		Test.setoX(0);
		Test.setoY(0);
		
		assertEquals(0, Test.getoX());
		assertEquals(0, Test.getoY());
		
		Test2.setName("Test");
		assertEquals("Test", Test2.getName());
		
	}
	
/**
* 	This method tests the saveString Method.
*  It helps to prove that the data the user expects
*  to be saved in a string is saved correctly.
*/
	@Test
	public void DiagramsaveStringTest(){
		DiagramImpl testDiagram = new DiagramImpl();
		ClassImpl testClass = new ClassImpl("TestClass");
		ClassImpl testClass1 = new ClassImpl("TestClass1");
		testClass.addAttribute("input", "int", '*');
		testClass1.addAttribute("output", "int", '&');
		testClass.addOperation("item", "string", '$');
		testClass1.addOperation("stuff", "bool", '#');
		testClass.setoX(0);
		testClass.setoY(0);
		testClass.setHeight(5);
		testClass.setWidth(10);
		testClass1.setoX(1);
		testClass1.setoY(1);
		testClass1.setHeight(4);
		testClass1.setWidth(8);
				
		testDiagram.addClass(testClass);
		testDiagram.addClass(testClass1);
		testDiagram.addRelationship(testClass.anchorAt(0), testClass1.anchorAt(5));
		
		String test = "2 1\nTestClass\n1 1\n0 0 5 10\n* input int\n$ item string\n\nTestClass1\n1 1\n1 1 4 8\n& output int\n# stuff bool\n\nTestClass TestClass1\n\n";
		
		assertEquals(testDiagram.saveString(), test);
	}
}